package com.CMC.yhdeng;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.CMC.yhdeng.QuizBaseActivity.QuizMode;
import com.CMC.yhdeng.QuizContent.QCState;

public class QuizColl {
private ArrayList<QuizContent> objs;
public ArrayList<QuizContent> getObjs() {
	return objs;
}

private int current=0;

public QuizColl( List<QuizContent> obj, QuizMode qm) {
	super();
	objs=new ArrayList<QuizContent>();
	for (QuizContent quizContent : obj) {
		if(
				(qm==QuizMode.QM_Practice && quizContent.is_practice.compareTo("1")==0)
				||
				(qm==QuizMode.QM_Test && quizContent.is_test.compareTo("1")==0)
				)
		{
			objs.add(quizContent);
		}
	}
	if(qm==QuizMode.QM_Test)
	{
		Random ra=new Random(System.currentTimeMillis());
		
		int n=objs.size()-1;
		for(int j=n; j>=0; --j)
		{
			int i=(int)(ra.nextFloat()*j);
			if(i==j) continue;
			QuizContent qc1=objs.get(i), qc2=objs.get(j), qcT=null;
			qcT=qc1;
			objs.set(i, qc2);
			objs.set(j, qcT);
		}
	}
}

public QuizContent next()
{
	if(current >objs.size()-1) return null;
	else return objs.get(current++);
}

public QuizContent getCurrent()
{
	return objs.get(current-1);
}

public int getCorrectPoints()
{
	int sum=0;
	for (QuizContent qc : objs) {
		if(qc.answerState==QCState.CORRECT) sum++;
	}
	return sum;
}

public int getWrongPoints()
{
	int sum=0;
	for (QuizContent qc : objs) {
		if(qc.answerState==QCState.WRONG) sum++;
	}
	return sum;
}
}
